package com.weipai.springboot.module.service.impl;

import com.weipai.springboot.enums.RetCode;
import com.weipai.springboot.model.CommissionRate;
import com.weipai.springboot.model.Freight;
import com.weipai.springboot.model.api.Response;
import com.weipai.springboot.module.dao.SystemDao;
import com.weipai.springboot.module.service.SystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author: 曹朋飞
 * @Date: 2018/09/01 10:56
 */
@Service
public class SystemServiceImpl implements SystemService{
    
    @Autowired
    private SystemDao systemDao;

    //保存员工提成比例
    @Override
    public Response saveCommissionRate(Integer type, Integer rate) {
        Response response = new Response();
        CommissionRate commissionRate = new CommissionRate();
        commissionRate.setCommissionRateType(type);
        commissionRate.setCommissionRate(rate);
        if(systemDao.saveCommissionRate(commissionRate)==1){
            response.setCode(RetCode.SUCCESS);
        }else{
            response.setCode(RetCode.REQUEST_ERROR);
        }
        return response;
    }

    //根据类型获得比例
    @Override
    public Response getCommissionRateByType(Integer type) {
        Response response = new Response();
        Map<String, Object> map = systemDao.getCommissionRateByType(type);
        if(null!=map && map.size()>0){
            response.setCode(RetCode.SUCCESS);
            response.setData(map);
        }else{
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }

    //修改提成比例
    @Override
    public Response updateCommissionRateById(Integer id, Integer rate) {
        Response response = new Response();
        if(systemDao.updateCommissionRateById(id, rate)==1){
            response.setCode(RetCode.SUCCESS);
        }else{
            response.setCode(RetCode.REQUEST_ERROR);
        }
        return response;
    }

    //获取运费
    @Override
    public Response getFreight() {
        Response response = new Response();
        Freight freight = systemDao.getFreight();
        if(null!=freight){
            response.setCode(RetCode.SUCCESS);
            response.setData(freight);
        }else{
            response.setCode(RetCode.NO_DATA);
        }
        return response;
    }

    //修改运费
    @Override
    public Response updateFreight(Integer freightId, Integer fullPackage, Integer freight) {
        Response response = new Response();
        if(1 == systemDao.updateFreight(freightId, fullPackage, freight)){
            response.setCode(RetCode.SUCCESS);
        }else{
            response.setCode(RetCode.REQUEST_ERROR);
        }
        return response;
    }
}
